Skip to content

[GH-3146] Keep M coordinates and write Z and M bounds in GeoParquet 2.0 files - #3562

Merged
jiayuasu merged 7 commits into
apache:masterfrom
jiayuasu:feature/geoparquet-2.0-m-coordinates
Nov 20, 2026
Merged

jiayuasu merged 7 commits into
apache:masterfrom
jiayuasu:feature/geoparquet-2.0-m-coordinates

Conversation

@jiayuasu

@jiayuasu jiayuasu commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Did you read the Contributor Guide?

Is this PR related to a ticket?

What changes were proposed in this PR?

The GeoParquet writer keeps X, Y and Z and discards M, because GeoParquet 1.1 has no M coordinate: its geometry_types only know the Z suffix. GeoParquet 2.0 has M. Its geometry_types allow M and ZM, and the GEOMETRY logical type of the Parquet format holds ISO WKB of all four layouts. After #3553 a 2.x write still dropped M.

With this PR a 2.x write keeps M:

  • The WKB writer of a 2.x file writes up to four ordinates, so XYM and XYZM geometries are stored as they are, with the ISO type codes 2001 to 2007 and 3001 to 3007.
  • geometry_types in the geo metadata name the layout from the stored type code: Point M, LineString ZM and so on.
  • On Spark 4.2 a native geometry value is stored as the WKB it holds, and the reader hands the stored WKB to a native value as it is. Both used to go through a JTS geometry, which has no coordinates to keep the Z and M dimensions of an empty multi-geometry or collection in: MULTIPOINT M EMPTY became MULTIPOINT EMPTY, and a GEOMETRYCOLLECTION M with such a member became a collection of members with two layouts, which Spark's native type rejects with WKB_PARSE_ERROR. The same happened with Z before this PR, on the write and on the read. A column of GeometryUDT is not affected, because its values come from JTS geometries. The writer converts a native value to WKB once and reads the JTS geometry for the metadata from the same bytes. The reader still goes through a JTS geometry for WKB that Spark does not take as it is, such as a line of one point or a ring that is not closed, which the WKB reader completes.
  • The bbox of a column in the geo metadata of a 2.x file lists the bounds of every dimension that has them, as GeoParquet 2.0 asks: six values for a column with Z coordinates, [xmin, ymin, zmin, xmax, ymax, zmax], and eight for a column with Z and M coordinates, [xmin, ymin, zmin, mmin, xmax, ymax, zmax, mmax]. The writer had the X and Y bounds only, so a column with XYZ geometries had four values after [GH-3146] Write GeoParquet 2.0 files with the Parquet GEOMETRY type #3553. A column with M and without Z coordinates keeps its four values, because the specification has no bbox with M bounds and without Z bounds. A Z or M coordinate that is NaN is not a bound, as in the bounding box of the Parquet statistics, and a dimension without a coordinate that is a number is left out. The reader takes the X and Y bounds of such a bbox since [GH-3560] Read the X and Y bounds of a GeoParquet bbox that has Z or M bounds #3561.
  • A column with a bound that is infinite or NaN has no bbox. JSON has no number for such a bound: the writer stored the string "Infinity" or null in its place, which the GeoParquet schema does not allow. This applies to the X and Y bounds of a 1.x file too.

What stays the same:

  • GeoParquet 1.x writes. They discard M as before, therefore still write a native value again from its JTS geometry, and keep the four values of the X and Y bounds in the bbox.

Sedona 1.9.1 reads a bbox of six or eight values as if it had four (#3560). It does not get that far with a 2.0 file: on Spark 3.5 and 4.0 it cannot read the footer, and on Spark 4.1 the read fails unless Spark's geospatial feature is enabled, and then the column has Spark's native type, which the functions of 1.9.1 do not take.

Known limit: the geometry types in the row-group statistics come from parquet-java. It skips empty geometries and takes the Z and M dimensions from the first coordinate, so LINESTRING M (1 2 NaN, 3 4 99) is stored with type code 2002 and listed as LineString M in geometry_types, while the statistics report type 2. #3553 notes the same for Z, and Spark's own writer produces the same statistics. parquet-java computes them from the stored WKB while it writes the column, so the fix belongs there.

How was this patch tested?

GeoParquetDimensionsSuite has a new test that writes XYM and XYZM points and lines, empty XYM and XYZM geometries, and XY and XYZ points to a 2.0 file. It compares the stored bytes with the ISO WKB of the input, checks geometry_types, compares the types in the row-group statistics with the geometries that have coordinates, checks the eight values of the bbox, and reads the file back with the geoparquet reader. On Spark 4.2 it runs for a native geometry column and for a GeometryUDT column. For the native column it also writes empty multi-geometries with M, ZM and Z and collections with an empty member, and compares ST_AsBinary of the values read back with the input.

Fifteen more tests check the bbox of one column each: XYM geometries, XYZ geometries, XYZ next to XYM geometries, Z and M coordinates that are NaN in some or in all geometries, XYZ geometries in a 1.1 file, an infinite M next to no Z, and the columns that get no bbox because an X, Y, Z or M coordinate is infinite or a Y coordinate is NaN. Those files are read back with a spatial filter. Two further tests cover the single conversion of a value on the write and the read of a line of one point and of a ring that is not closed. The existing tests still cover that a 1.1 write discards M.

The GeoParquet suites pass locally on Spark 4.2 / Scala 2.13 (including the GeoParquet suites of the spark-4.2 module), Spark 4.1 / Scala 2.13 and Spark 3.5 / Scala 2.12.

Did this PR include necessary documentation updates?

  • Yes, I have updated the documentation.

The GeoParquet writer keeps X, Y and Z and discards M, because GeoParquet
1.1 has no M coordinate. GeoParquet 2.0 has one: its geometry_types allow
the M and ZM suffixes, and the GEOMETRY logical type of the Parquet
format holds ISO WKB of all four layouts.

A 2.x write now stores XYM and XYZM geometries as they are, and
geometry_types name the layout from the stored type code. A 1.x write
discards M as before.
…ox without all bounds

A native Spark geometry value holds WKB, and it keeps the Z and M
dimensions that an empty multi-geometry or collection declares. A JTS
geometry has no coordinates to keep them in. The writer and the reader
both went through JTS, so MULTIPOINT M EMPTY became MULTIPOINT EMPTY, and
a GEOMETRYCOLLECTION M with such a member became a collection of members
with two layouts, which Spark's native type rejects. The same happened
with Z before this change.

A 2.x write now stores the WKB of a native value as it is, and the reader
hands the stored WKB to a native value as it is. A 1.x write still goes
through JTS, because it has to discard M.

GeoParquet 2.0 asks for the bounds of all four dimensions in the bbox of
a column with XYZM geometries. The writer has the X and Y bounds only, so
it leaves the optional bbox out for such a column.

The test compares the types in the row-group statistics with
geometry_types for the geometries that have coordinates.
The bbox of a column in the geo metadata of a 2.x file now lists the bounds
of every dimension that has them: six values for a column with Z
coordinates and eight for a column with Z and M coordinates. A column with
XYZM geometries had no bbox, so its files could not be skipped. GeoParquet
1.x files keep the four values of the X and Y bounds.
@jiayuasu
jiayuasu force-pushed the feature/geoparquet-2.0-m-coordinates branch from 153c78b to 1672729 Compare November 20, 2026 08:00
@jiayuasu jiayuasu changed the title [GH-3146] Keep M coordinates in GeoParquet 2.0 files [GH-3146] Keep M coordinates and write Z and M bounds in GeoParquet 2.0 files Nov 20, 2026
@jiayuasu jiayuasu added this to the sedona-2.0.0 milestone Nov 20, 2026
@jiayuasu
jiayuasu merged commit d7e0205 into apache:master Nov 20, 2026
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant